package com.fly.platform.conf.mybatisplus


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler
import com.fly.platform.base.service.IUserService
import org.apache.ibatis.reflection.MetaObject
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import java.util.*

/**
 * 字段填充审计
 * @author Fei
 */
@Component
class MyMetaObjectHandler : MetaObjectHandler {

    @Autowired
    private lateinit var userService: IUserService

    override fun insertFill(metaObject: MetaObject) {

       /* val principal = SecurityContextHolder.getContext().authentication.principal
        if ("anonymousUser" != principal.toString()) {
            val user = principal as UserDetails
            this.setFieldValByName("createBy", userService.findByUsername(user.username).getId(), metaObject)
        }*/
        this.setFieldValByName("createTime", Date(), metaObject)
    }

    override fun updateFill(metaObject: MetaObject) {

       /* val principal = SecurityContextHolder.getContext().authentication.principal
        if ("anonymousUser" != principal.toString()) {
            val user = principal as UserDetails
            this.setFieldValByName("updateBy", userService.findByUsername(user.username).getId(), metaObject)
        }*/
        this.setFieldValByName("updateTime", Date(), metaObject)
    }
}